package com.example.wendao.model.service;

import androidx.paging.DataSource;

import com.example.wendao.model.db.dao.FansDao;
import com.example.wendao.model.db.database.AppDatabase;
import com.example.wendao.model.entity.Fans;
import com.example.wendao.model.entity.User;


public class FansService {

    private FansDao fansDao;

    //构造
    public FansService(){
        fansDao = AppDatabase.getDatabases().getFansDao();
    }



    //更新
    public void updateFan(Fans fan){
        fansDao.updateFan(fan);
    }

    //关注
    /*
    * param:粉丝类
    * return:空
    * */
    public void follow(Fans fans){
        fansDao.follow(fans);
    }

    //查询关系
    /*
    * param:粉丝id   被关注者id
    * return:粉丝类
    * */
    public Fans queryIsFollow(int beFollowerId, int followerId){
        return fansDao.queryIsFollow(beFollowerId, followerId);
    }

    public void insertFans(Fans... fans){
        fansDao.insertFans(fans);
    }

    //查询粉丝
    /*
     * param:被关注者id
     * return:分页粉丝列表的数据源工厂
     * */
    public DataSource.Factory<Integer, User> queryAllFans(int beFollowerId){
        return fansDao.queryAllFans(beFollowerId);
    }

    //查询关注
    /*
     * param:粉丝id
     * return:分页被关注者列表的数据源工厂
     * */
    public DataSource.Factory<Integer, User> queryAllFollower(int followerId){
        return fansDao.queryAllBeFollower(followerId);
    }

    //设置互关   在A关注B时，若B已关注了A，则可调用次函数来让之前B关注A的那一条记录的互关字段变为1
    /*
     * param:粉丝id    被关注者id
     * return:空
     * */
    public void followEachOther(int beFollowerId ,int followerId){
        fansDao.followEachOther(beFollowerId, followerId);
    }

}
